// 获取列表
export function getList() {
  return new Promise((resolve, reject) => {
    const db = wx.cloud.database();
    db.collection('list').where({}).get({
      success: function (res) {
        resolve(res)
      },
      fail: function (err) {
        reject(err)
      }
    })
  })
}
// 获取详情
export function getInfo(_id) {
  return new Promise((resolve, reject) => {
    const db = wx.cloud.database();
    db.collection('list').doc(_id).get().then(res => resolve(res)).catch(err => reject(err));
  })
}

// 新增数据
export function addList(data = {}) {
  return new Promise((resolve, reject) => {
    const db = wx.cloud.database();
    db.collection('list').add({
      data
    }).then(res => resolve(res)).catch(err => reject(err));
  })
}

// 更新数据
export function updateList(data = {}) {
  return new Promise((resolve, reject) => {
    const db = wx.cloud.database();
    db.collection('list').doc(data._id).update({
      data: {
        content: data.content,
        date: data.date,
        time: data.time,
        title: data.title
      }
    }).then(res => resolve(res)).catch(err => reject(err));
  })
}